<?php
include_once "models/report_model.php"; 
include_once "controllers/backend_controller.php"; 
class Report_Controller extends Backend_Controller
{
	public $model; 
	public $action = "lists";
   public function  __construct() 
   {
		$this->model = new Report_Model();
		if(isset($_GET["action"])) $this->action = $_GET["action"];
		$this->{$this->action}();
   }

	public function add() 
	{

		if(isset($_POST["btn_submit"])) {
			$title = $_POST["title"];
			$content = $_POST["content"];
			$this->model->addReport($title, $content);

			include "views/repost/success.php";
		} else

			include "views/repost/addreport.php";
       // exit("manhha");
	}

	public function lists() 
	{
		$listReports = $this->model->getListReports(); 
		include "views/repost/reportlist2.php";
	}

	public function view1($id)
	{  $listReports = $this->model->getListReports();
	   $buffer = array_slice($listReports,$id,1);
	   $reportView = array();
	   foreach ($buffer as $key =>$value)
	   {
	     $reportView[]=$value['title'];
		 $reportView[]=$value['content'];
		 $reportView[]=$value['status'];
	   }
	   include "views/repost/reportview.php";
	}
    // Method get view along id
    public  function view(){
        $id = $_GET['id'];
        $listReports = $this->model->getReport($id);
        include'views/repost/reportview.php';

    }
    //Method edit
    public  function edit(){
        $id = $_POST['id'];
        $title = $_POST['title'];
        $content = $_POST['content'];
        $this->model->editReport($id,$title,$content);
        $listReports = $this->model->getListReports();
        include'views/repost/reportlist2.php';

    }
    //Go page before Edit
    public function beforeedit(){
        $id = $_GET['id'];
        $listReport = $this->model->getReport($id);
        include'views/repost/EditReport.php';

    }
    //Method delete
    public function delete(){
        $id = $_GET['id'];
        $this->model->deleteReport($id);
        $listReports = $this->model->getListReports();
        include'views/repost/reportlist2.php';

    }

    public function ajaxLists()
    {
        $listReports = $this->model->getListReports();
        include "views/repost/reportlistajax.php";
    }
}
?>